package crm.view.desktop.iFrame;

import java.awt.CardLayout;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JInternalFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;

import crm.model.teacherPC.Manager;
import crm.model.teacherPC.net.PcWindow;
import crm.model.teacherPC.net.StudentPC;
import crm.view.desktop.iFrame.bar.IFrameFunktBar;
import crm.view.desktop.iFrame.views.DesktopVisualisizer;
import crm.view.desktop.iFrame.views.HistorieListModel;
import crm.view.desktop.iFrame.views.WindowList;
import crm.view.desktop.iFrame.views.desktopvisualizer.StudentPopup;
import crm.view.popup.WindowPopup;




public class StudentFrame extends JInternalFrame implements MouseListener, InternalFrameListener, ComponentListener {
	StudentPC student;
	private IFrameFunktBar tool;
	private JList jList1;
	private JList historieList;
	private DesktopVisualisizer desktopVisualisizer;
	private JTabbedPane jTabbedPane1;
	Manager m;
	public StudentFrame(StudentPC student, Manager m){
	    super(student.getUser(),
	            true, //resizable
	            true, //closable
	            true, //maximizable
	            true);//iconifiable
		this.student=student;
		this.m=m;
		setSize(200, 200);
		addInternalFrameListener(this);
		addComponentListener(this);
		createGUI();
		setVisible(true);
		setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);

	}
	private void createGUI() {
		try {
			{
				this.setPreferredSize(new java.awt.Dimension(320, 221));
				{
					JPanel contend = new JPanel(new CardLayout());
					this.setContentPane(contend);

						{
							jList1 = new JList();
							jList1.addMouseListener(this);
							contend.add(new JScrollPane(jList1), "Windows");
							jList1.setModel(new WindowList(student, m));
						}
						{
							desktopVisualisizer = new DesktopVisualisizer(student, m);
							desktopVisualisizer.addMouseListener(this);
							contend.add(desktopVisualisizer, "Desktop");
						}
						{
							historieList = new JList();
							historieList.addMouseListener(this);
							contend.add(new JScrollPane(historieList), "History");
							historieList.setModel(new HistorieListModel(student, m));
						}

					{
						tool = new IFrameFunktBar(this);

					}
				}
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	public void mouseClicked(MouseEvent ev) {
		if (ev.getButton() == MouseEvent.BUTTON3){
			if (ev.getComponent() instanceof JList){
				PcWindow w = (PcWindow)jList1.getSelectedValue();
				WindowPopup.show(w, this, ev.getX(), ev.getY());
			}else if (ev.getComponent() instanceof DesktopVisualisizer){

				StudentPC s = desktopVisualisizer.student;
				StudentPopup.show(s, this, ev.getX(), ev.getY());
			}
		}


	}
	public StudentPC getStudent() {
		return student;
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		tool.show(this, 0, tool.getHeight() * (-1));
	}
	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}
	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}
	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}
	@Override
	public void internalFrameActivated(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub

	}
	@Override
	public void internalFrameClosed(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub

	}
	@Override
	public void internalFrameClosing(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub

	}
	@Override
	public void internalFrameDeactivated(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub

	}
	@Override
	public void internalFrameDeiconified(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub

	}
	@Override
	public void internalFrameIconified(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub

	}
	@Override
	public void internalFrameOpened(InternalFrameEvent arg0) {
		// TODO Auto-generated method stub

	}
	@Override
	public void componentHidden(ComponentEvent e) {
		// TODO Auto-generated method stub

	}
	@Override
	public void componentMoved(ComponentEvent e) {
//		tool.setLocation(getLocation().x, getLocation().y-tool.getSize().height);

	}
	@Override
	public void componentResized(ComponentEvent e) {
		// TODO Auto-generated method stub

	}
	@Override
	public void componentShown(ComponentEvent e) {
		// TODO Auto-generated method stub

	}

}
